import React, { useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { hide } from '@/store/slice/myToast'

export default function MyToast() {
    // 把 提示内容放在 redux 里面
    const { text, show } = useSelector((state: IRootState) => state.myToast)
    const dispatch = useDispatch()

    // 只有当 show 为true的时候，才需要过一会变成false
    if (show) {
        setTimeout(() => {
            console.log(123)
            dispatch(hide())
        }, 3000);
    }


    return (
        <div style={{ display: show ? 'block' : 'none' }}>{text}</div>
    )
}
